<%@ Page Language="C#" AutoEventWireup="true" CodeFile="dynAjax.aspx.cs" Inherits="javascript_dynAjax" %>
/**********************************************************************
 * DYNAJAX Project [v1.06] - code by Benoit BEGUIN
 * first release: october 2007
 * last update: october 2008
 * Paris, France
 * 
 * DynAjax web site: http://www.dynajax.org/
 * DynAjax samples web site: http://samples.dynajax.org/
 * DynAjax download: http://download.dynajax.org/
 * Any question: mailto:admin@dynajax.org
 * Company support: http://www.odesys.fr
 **********************************************************************/

/* ------- GENERIC CONTENT ------- */
var DynAjaxManager = Class.create();

DynAjaxManager.prototype = {
    initialize: function() {},
    getDynaData: function(classId, methodName, args, callBackMethod) {
        var dynaResult = null;
        var asyncCall = false;
        if (callBackMethod && typeof callBackMethod == "function") {
            asyncCall = true;
        }
        
        new Ajax.Request('AjaxDataHandlers/DynAjaxHandler.aspx',
            {   method: "post",
                asynchronous: asyncCall,
                parameters: "classId=" + encodeURIComponent(classId) + "&methodName=" + encodeURIComponent(methodName) + "&methodArgs=" + encodeURIComponent(Object.toJSON(args)),
                onSuccess: function(request){
                    dynaResult = request.responseText.evalJSON();
                    if (dynaResult.__DynAjaxException__19770110314159265__) {
                        throw dynaResult;
                    }
                    if (callBackMethod) {
                        callBackMethod(dynaResult);
                    }
                },
                onException: function(e) {
                    if (dynaResult && dynaResult.__DynAjaxException__19770110314159265__) {
                        var dynaExc = dynaResult.__DynAjaxException__19770110314159265__;
                        if (dynaExc.action == "JSMethod") {
                            dynaResult = null;
                            eval(dynaExc.parameter + "()");
                        }
                        else if (dynaExc.action == "JSEval") {
                            dynaResult = null;
                            eval(dynaExc.parameter);
                        }
                        else if (dynaExc.action == "returnValue") {
                            dynaResult = dynaExc.parameter;
                        }
                    }
                    else {
                        dynaResult = null;
                    }
                    if (callBackMethod) {
                        callBackMethod(dynaResult);
                    }
                }
            });
        return dynaResult;
    }
};
var dynAjaxManager = new DynAjaxManager();
/* ------- END OF GENERIC CONTENT ------- */

/* ------- DYNAMIC CONTENT ------- */
<%= dynamicJsText %>
/* ------- END OF DYNAMIC CONTENT ------- */